import request from "../../utils/reuqest";
import { LandInfoData, UpdateLandStatusRes, LandInfoItem, position, deleteAddress, findLandInfo, editLandInfo, AddLandForm, LandFormData, addLandInfo } from '../../types/land'

export function getAllLand(params: any): Promise<LandInfoData> {
    return request.get<any, LandInfoData>(`/admin/admin/getAllLand`, { params });
}

/** 
 * 修改土地状态
 * @param {number} status 
 * @param {number} id 
 * @returns
 */
export function updateLandStatus(status: number, id: number): Promise<UpdateLandStatusRes> {
    return request.post(`/admin/admin/status/${status}?id=${id}`);
}

/**
 * 新增土地信息 - 使用专门的AddLandForm类型
 * @param {AddLandForm} params 
 * @returns
 */
export function addLand(params: AddLandForm): Promise<addLandInfo> {
    return request.post(`/admin/admin/addLand`, params);
}

/** 
 * 获取省市区
 * @param {number} pid 
 * @returns
 */
export function checkProvincesMunicipalities(pid: number): Promise<position> {
    return request.get(`/checkProvincesMunicipalities?pid=${pid}`);
}

/** 
 * 根据id删除土地
 * @param {number} id 
 * @returns
 */
export function deleteLandById(id: number): Promise<deleteAddress> {
    return request.delete(`/admin/admin/deleteLandById?id=${id}`);
}

/** 
 * 根据id查找土地信息（回显）
 * @param {number} id 
 * @returns
 */
export function getLandById(id: number): Promise<findLandInfo> {
    return request.get(`/admin/admin/getLandById?id=${id}`);
}

/**
 * 确认编辑土地 - 使用专门的EditLandForm类型
 * @param {EditLandForm} farmlandInfo
 * @returns
 */
export function updateLandById(farmlandInfo: LandFormData): Promise<LandFormData> {
    return request.put(`/admin/admin/updateLand`, farmlandInfo);
}